function [res alerts] = TripBallence(mevents, thresh)

    alerts = cell(0,3);

    start = datenum(2011,5,0,0,0,0);
    stop  = datenum(2011,6,20,0,0,0);

    ndays = stop - start;
    ballence = zeros(ndays,2);


    for i = 1:ndays

        oballence = 0;
        if i > 1
            oballence = ballence(i-1,2);
        end

        day = start + i;

        dloss = 0;
        for j = 1:length(mevents)
            estart = mevents{j}{2};
            estop  = estart + (mevents{j}{3} - 1);
            edens  = mevents{j}{1} / mevents{j}{3};
            if day >= estart && day <= estop
                if abs(edens) >= thresh*oballence
                    % add this to the alerts for this day...
                    index = -1;
                    for k = 1:size(alerts,1)
                        if alerts{k,2} == day
                            index = k;
                        end
                    end
                    if index == -1
                        index = size(alerts,1) + 1;
                        alerts{index,1} = index;
                        alerts{index,2} = day;
                        alerts{index,3}{1,1} = mevents{j}{4};
                        alerts{index,3}{1,2} = edens;                        
                    else
                        alerts{index,1} = index;
                        alerts{index,2} = day;
                        tindex = size(alerts{index,3},1) + 1;
                        alerts{index,3}{tindex,1} = mevents{j}{4};
                        alerts{index,3}{tindex,2} = edens;                        
                    end
                end
            %        fprintf('%f\t\t%f | %f\n', day, estart, estop);
                dloss = dloss + edens;
            end
        end

        nballence = oballence + dloss;
        ballence(i,1) = day;
        ballence(i,2) = nballence;
    end


    res = ballence;
end


